package com.better.backend.mqReceiverService.questionReceiver.listener;

import com.alibaba.fastjson.JSONObject;
import com.better.backend.mqReceiverService.questionReceiver.model.ExamPaperModel;
import com.better.backend.mqReceiverService.questionReceiver.repository.ExamPaperRepsitory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author xiaq
 * 消息接收
 * @create 2017-09-23 12:01
 **/
@Component
public class ExamPaperReceiver {
    @Autowired
    private ExamPaperRepsitory examPaperRepsitory;
    private static Log log = LogFactory.getLog(ExamPaperReceiver.class);
    @RabbitListener(queues = "zxy_addQuestion")
    public void process(Message examModel) {
        String a = new String(examModel.getBody());
        log.info("接收考试题目消息：topic==zxy_addQuestion。"+a);
        ExamPaperModel examPaper = JSONObject.parseObject(a, ExamPaperModel.class);
        examPaperRepsitory.save(examPaper);
    }
}
